package com.audaque.springboot.foshanupload.web.mpdemo.mpgt.action;

import com.audaque.springboot.foshanupload.mp.util.MybatisParameterUtils;
import com.audaque.springboot.foshanupload.web.mpdemo.mpgt.mapper.SysUserMpgtMapper;
import com.audaque.springboot.foshanupload.web.mpdemo.mpgt.model.pojo.SysUserMpgtPojo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import jodd.madvoc.meta.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author zgb
 * @desc in 处理
 * @date 2023-05-29 09:13:32
 */
@RestController
@RequestMapping("cutInParameter")
public class CutInParameterController {

    @Autowired
    private SysUserMpgtMapper sysUserMpgtMapper;


    @Operation(summary = "列表查询")
    @RequestMapping(value = "/run", method = {RequestMethod.POST})
    public  List<SysUserMpgtPojo> run(@RequestBody SysUserMpgtPojo sysUserMpgtPojo) throws Exception {
        //条件构造器
        LambdaQueryWrapper<SysUserMpgtPojo> queryWrapper = new LambdaQueryWrapper<>();

        //普通字段查询
        queryWrapper.eq(!StringUtils.isEmpty(sysUserMpgtPojo.getAvatar()),SysUserMpgtPojo::getAvatar,sysUserMpgtPojo.getAvatar());
        //从requestParam加工得到的参数传给mybatisplus的in,避免参数为空集合
        List<Long> orgIdList = sysUserMpgtPojo.getOrgIdList();
        orgIdList.add(-1L);
        //调用工具类重新拼装in条件               （条件wrapper，            get方法的方法引用，    参数list）
        MybatisParameterUtils.cutInParameter(queryWrapper,SysUserMpgtPojo::getOrgId,orgIdList );

        List<SysUserMpgtPojo> list = sysUserMpgtMapper.selectList(queryWrapper);
        return list;
    }

}
